﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace InversPong
{
    class OptionEntryBoxScreen : MessageBoxScreen
    {
        #region Fields
        Keys keytoAccept;

        #endregion

        #region Events

        public event EventHandler<PlayerTypedKey> KeyTyped;

        #endregion

        #region Initialization

        public OptionEntryBoxScreen(string message)
            : this(message, false)
        { }

        public OptionEntryBoxScreen(string message, bool includeUsageText)
            : base(message, includeUsageText)
        {
        }

        #endregion

        #region Inputs

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            Keys[] keyState = input.CurrentKeyboardStates[(int)ControllingPlayer + 1].GetPressedKeys();

            
            if (keyState.Length > 0)
            {
                if(keyState[0] != Keys.Enter)
                keytoAccept = keyState[0];
            }
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                if (KeyTyped != null)
                    KeyTyped(this, new PlayerTypedKey(playerIndex, keytoAccept));
                    
            }


            base.HandleInput(input);
        }
        #endregion

    }
}
